package com.piggy.logi.sys.controller;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.api.vo.LogiSysDeptExtVo;
import com.piggy.logi.sys.api.bo.LogiSysDeptExtCusEditBo;
import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.bo.LogiSysDeptExtQueryBo;
import com.piggy.logi.sys.service.ILogiSysDeptExtService;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.piggy.common.core.domain.R;

import java.lang.Integer;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * 部门扩展信息Controller
 *
 * @author piggy
 * @date 2023-08-10
 */
@Api(value = "部门扩展信息控制器", tags = {"部门扩展信息管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/logi/deptExt")
public class LogiSysDeptExtController extends BaseController {

    private final ILogiSysDeptExtService iLogiSysDeptExtService;

    /**
     * 查询部门扩展信息列表
     */
    @ApiOperation("查询部门扩展信息列表(分页查询)")
    @PostMapping("/list")
    public TableDataInfo<LogiSysDeptExtVo> list(@Validated @RequestBody LogiSysDeptExtQueryBo bo) {
        return iLogiSysDeptExtService.queryPageList(bo);
    }

    /**
     * 导出部门扩展信息列表
     */
    @ApiOperation("查询部门扩展信息列表")
    @PostMapping("/list1")
    public R<List<LogiSysDeptExtVo>> list1(@Validated @RequestBody LogiSysDeptExtQueryBo bo) {
        return R.ok(iLogiSysDeptExtService.queryList(bo));
    }

    /**
     * 导出部门扩展信息列表
     */
    @ApiOperation("查询部门信息")
    @GetMapping("/getByDeptId/{deptId}")
    public R<LogiSysDeptExtVo> getByDeptId(@PathVariable("deptId")Long deptId) {
        return R.ok(iLogiSysDeptExtService.queryByDeptId(deptId));
    }

    /**
     * 导出部门扩展信息列表
     */
    @ApiOperation("导出部门扩展信息列表")
    @LogiLog(title = "部门扩展信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiSysDeptExtQueryBo bo, HttpServletResponse response) throws IOException {
        List<LogiSysDeptExtVo> list = iLogiSysDeptExtService.queryList(bo);
        ExcelUtil<LogiSysDeptExtVo> util = new ExcelUtil<LogiSysDeptExtVo>(LogiSysDeptExtVo.class);
        util.exportExcel(response, list, "部门扩展信息");
    }

    /**
     * 获取部门扩展信息详细信息
     */
    @ApiOperation("获取部门扩展信息详细信息")
    @GetMapping("/{id}")
    public R<LogiSysDeptExtVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable("id") Long id) {
        return R.ok(iLogiSysDeptExtService.queryById(id));
    }

    /**
     * 新增部门扩展信息
     */
    @ApiOperation("新增部门扩展信息")
    @LogiLog(title = "部门扩展信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiSysDeptExtVo> add(@Validated @RequestBody LogiSysDeptExtCusEditBo bo) {
        return R.ok(iLogiSysDeptExtService.insertByAddBo(bo));
    }

    /**
     * 修改部门扩展信息
     */
    @ApiOperation("修改部门扩展信息")
    @LogiLog(title = "部门扩展信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiSysDeptExtVo> edit(@Validated @RequestBody LogiSysDeptExtCusEditBo bo) {
        return R.ok(iLogiSysDeptExtService.updateByEditBo(bo));
    }

    /**
     * 删除部门扩展信息
     */
    @ApiOperation("删除部门扩展信息")
    @LogiLog(title = "部门扩展信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                             @PathVariable Long[] ids) {
        return R.ok(iLogiSysDeptExtService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
